package cn.com.firmlink.rms.component.validator
{
	import mx.validators.ValidationResult;
	import mx.validators.Validator;
	
	public class PTValidator extends Validator
	{
		private var results:Array;
		
		private var availablePayMethod:Array = ['DP','DA','OA','LC'];

		public function PTValidator()
		{
			super();
		}
		
		override protected function doValidation(value:Object):Array{
			var s:String = value as String;
            results = [];                           //清空数组
            results = super.doValidation(value);    //先用继承类中的doValida tion方法验证
            if (results.length > 0) {                //如果验证时有错，返回错误信息
                return results;
            }
            var arr:Array = value.split(" ");
            
			if(arr.length != 2){
        		results.push(new ValidationResult(true,"text","errorFormater", "格式错误，有效格式为## ##!"));
        	}else{
        		var payMethod = arr[0];
				var payPeriod = arr[1];
				if(availablePayMethod.indexOf(payMethod)<0){
					results.push(new ValidationResult(true,"text","invalidPayMethod", "PayMethod取值错误，有效值为['DP','DA','OA','LC']"));
				}
				
        	}

            return results;
		}
		
		public function get errorMessages():String{
			var errorMessages:String="";
			for(var i:Number=0; i< results.length; i++){
				var err:ValidationResult = results[i];
				errorMessages += err.errorMessage +"\n";
			}
			return errorMessages;
		}

	}
}